package com.projectName.www.servlet;

import com.projectName.www.dao.OrderDaoImpl;
import com.projectName.www.po.Order;
import com.projectName.www.po.User;
import com.projectName.www.service.UserService;
import com.projectName.www.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/orderServlet")
public class OrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //the first step
        //from Dao get orderLists

        req.setCharacterEncoding("utf-8");

        UserService us=new UserServiceImpl();
        List<Order> orderList = us.findAllOrder();
        req.getSession().setAttribute("orderList",orderList);

        //the second step

        UserService service=new UserServiceImpl();
        List<User> users=service.findall();//all users


        req.getSession().setAttribute("users",users);

        //the last step   go to leading end
        req.getRequestDispatcher("/orderlist.jsp").forward(req,resp);

    }
}
